<template>
    <div>
        <div class="config">
            <div class="back" onclick="window.history.go(-1)"><img src="../assets/images/back.png" alt=""></div>
            <p>本月收益详情</p>
        </div>
        <div class="header">

        </div>
        <div class="box">
            <div class="row" v-for="item in data">
                <p>{{item.des}}</p>
                <p>{{item.create_time}}</p>
                <span>＋¥ {{item.price}}</span>
            </div>
            <p class="none" v-show="data.length==0">本月暂无记录</p>
        </div>

    </div>
</template>

<script>
export default {
    name: "mouthIncome",
    data() {
        return {
            data: {}
        };
    },
    beforeCreate() {
        document.getElementsByTagName("body")[0].style.background = "#ececec";
    },
    mounted() {
        var date = new Date();
        var month = date.getMonth() + 1;
        var year = date.getFullYear();
        var qs = require("qs");

        if (this.$route.params.code == "xf") {
            this.axios({
                method: "post",
                url: `${this.siteUrl}/getCostIncome`,
                data: qs.stringify({
                    uid: localStorage.getItem("uid"),
                    year: year,
                    month: month
                })
            })
                .then(response => {
                    console.log(response);
                    if (response.data.result == 200) {
                        this.data = response.data.data;
                        for (var i in this.data) {
                            this.data[i].create_time = new Date(
                                this.data[i].create_time
                            ).toLocaleDateString();
                        }
                    } else {
                        alert("请求失败");
                    }
                })
                .catch(function(error) {
                    console.log(error);
                });
        } else if (this.$route.params.code == "zs") {
            this.axios({
                method: "post",
                url: `${this.siteUrl}/getBusinessIncome`,
                data: qs.stringify({
                    uid: localStorage.getItem("uid"),
                    year: year,
                    month: month
                })
            })
                .then(response => {
                   
                    if (response.data.result == 200) {
                        this.data = response.data.data;
                        for (var i in this.data) {
                            this.data[i].create_time = new Date(
                                this.data[i].create_time
                            ).toLocaleDateString();
                        }
                    } else {
                        alert("请求失败");
                    }
                })
                .catch(function(error) {
                    console.log(error);
                });
        }
    }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.header {
    height: 120px;
    background: #5aa0c8;
    text-align: center;
}

.box {
    width: 94%;
    margin-left: 3%;

    border-radius: 3px;
    background: #fff;
    margin-top: -40px;
    overflow: hidden;
}

.row {
    min-height: 60px;
    background: #fff;
    position: relative;
    border-bottom: 1px solid #f2f2f2;
    margin: 8px;
}

.row span {
    position: absolute;
    height: 12px;
    top: 13px;
    right: 17px;
    color: #5aa0c8;
}

.row p:first-child {
    margin-left: 10px;
    margin-top: 5px;
    font-size: 14px;
    width: 70%;
}
.row p:nth-child(2) {
    margin-left: 10px;
    margin-bottom: 10px;
    font-size: 14px;
    color: #666;
}
.none {
    height: 60px;
    line-height: 60px;
    text-indent: 10px;
}
</style>
